﻿using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Linq;
using ReflectionStudio.Core.Events;
namespace WPFExcelReport
{
    public partial class TSHAP02
    {
        public TSHAP02()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VAPFOLGE();
            this.DataContext = MV;
            InitializeComponent();
        }
        public override void OnEXAUFChg(string vlaue)
        {
            //                KEY = TMV.APFANRKRS + TMV.APFALFDNR + TMV.APFAFOLGE + TMV.APFKSTKRS + TMV.APFKST + TMV.APFAGANG;
            TBMain.Clear();
            if (EXAUF.Length < 23)
                return;
            dwData = TBMain.NewRow();
            dwData["APFMANDANT"] = app.Mandant;
            dwData["APFANRKRS"] = " AND APFANRKRS ='"+ EXAUF.Substring(11, 2)+"'";
            dwData["APFALFDNR"] = " AND APFALFDNR = '" + EXAUF.Substring(13, 6) + "'";
            SResult = TMV.QAPF09(dwData);
            MergeData(SResult, true);
            base.OnEXAUFChg(vlaue);
        }
        public int currentpos = 0;
        public  string APKTEST(Dictionary<string, object> pm)
        {
            
            string result = "";
            vwMaster.View.MoveCurrentTo(-1);
            int cnt = TBMain.Rows.Count;
            bool found = false;
            string YN = " ";
            string condtions = "";
            string test = "";
            currentpos = 0;
            for (int i = currentpos; i < cnt; i++)
            {
                vwMaster.View.MoveCurrentToPosition(i);
                YN = TMV.APFNEGFBKL;
                #region======颜色组====

                condtions = TMV.APFFBKL1 + ";" + TMV.APFFBKL2 + ";" + TMV.APFFBKL3 + ";" + TMV.APFFBKL4 + ";" + TMV.APFFBKL5 + ";";
                test = pm["WAFFDVF"].ToString() + ";";
                if (YN == " "|| YN == "J")
                {
                    if (!condtions.Contains(test))
                        continue;
                }
                else
                {
                    if (condtions.Contains(test))
                        continue;
                }
                YN = TMV.APFNEGRGRP;
                #endregion
                YN = TMV.APFNEGRGRP;
                #region======整理方式/设置组====

                condtions = TMV.APFRUESTGRP1 + ";" + TMV.APFRUESTGRP2 + ";" + TMV.APFRUESTGRP3 + ";" + TMV.APFRUESTGRP4 + ";" + TMV.APFRUESTGRP5 + ";";
                test = pm["WAFRUESTGRP"].ToString() + ";";
                if (YN == " " || YN == "J")
                {
                    if (!condtions.Contains(test))
                        continue;
                }
                else
                {
                    if (condtions.Contains(test))
                        continue;
                }
                #endregion

                YN = TMV.APFNEGSUBST;
                #region======材质1====

                condtions = TMV.APFSUBSTGR1 + ";" + TMV.APFSUBSTGR2 + ";" + TMV.APFSUBSTGR3 + ";" + TMV.APFSUBSTGR4 + ";" + TMV.APFSUBSTGR5 + ";";
                test = pm["WASUBSTGR"].ToString() + ";";
                if (YN == " " || YN == "J")
                {
                    if (!condtions.Contains(test))
                        continue;
                }
                else
                {
                    if (condtions.Contains(test))
                        continue;
                }

                #endregion
                YN = TMV.APFNEGGEW;
                #region======克重1====

                condtions = TMV.APFGEW1 + ";" + TMV.APFGEW2 + ";";
                test = pm["WAHANDICAP"].ToString() + ";";
                if (YN == " " || YN == "J")
                {
                    if (!condtions.Contains(test))
                        continue;
                }
                else
                {
                    if (condtions.Contains(test))
                        continue;
                }
                #endregion
                YN = TMV.APFNEGBHDLG;
                #region======经密1====

                condtions = TMV.APFBHDLG1 + ";" + TMV.APFBHDLG2 + ";" + TMV.APFBHDLG3 + ";" + TMV.APFBHDLG4 + ";" + TMV.APFBHDLG5 + ";";
                test = pm["WAVORBWA"].ToString() + ";";
                if (YN == " " || YN == "J")
                {
                    if (!condtions.Contains(test))
                        continue;
                }
                else
                {
                    if (condtions.Contains(test))
                        continue;
                }
                #endregion
                YN = TMV.APFNEGBHDLG2;
                #region======长短纤1====

                condtions = TMV.APFBHDLG21 + ";" + TMV.APFBHDLG22 + ";" + TMV.APFBHDLG23 + ";" + TMV.APFBHDLG24 + ";" + TMV.APFBHDLG25 + ";";
                test = pm["WAVORBFB"].ToString() + ";";
                if (YN == " " || YN == "J")
                {
                    if (!condtions.Contains(test))
                        continue;
                }
                else
                {
                    if (condtions.Contains(test))
                        continue;
                }

                #endregion
                YN = TMV.APFNEGBHDLG3;
                #region======组织1====

                condtions = TMV.APFBHDLG31 + ";" + TMV.APFBHDLG32 + ";" + TMV.APFBHDLG33 + ";" + TMV.APFBHDLG34 + ";" + TMV.APFBHDLG35 + ";";
                test = pm["WANACHBDR"].ToString() + ";";
                if (YN == " " || YN == "J")
                {
                    if (!condtions.Contains(test))
                        continue;
                }
                else
                {
                    if (condtions.Contains(test))
                        continue;
                }

                #endregion
                YN = TMV.APFNEGBHDLG4;
                #region======上浆1====

                condtions = TMV.APFBHDLG41 + ";" + TMV.APFBHDLG42 + ";" + TMV.APFBHDLG43 + ";" + TMV.APFBHDLG44 + ";" + TMV.APFBHDLG45 + ";";
                test = pm["WAVORBAP"].ToString() + ";";
                if (YN == " " || YN == "J")
                {
                    if (!condtions.Contains(test))
                        continue;
                }
                else
                {
                    if (condtions.Contains(test))
                        continue;
                }

                #endregion
                YN = TMV.APFNEGMERK1;
                #region======紧度1====

                condtions = TMV.APFMERK11 + ";" + TMV.APFMERK12 + ";" + TMV.APFMERK13 + ";" + TMV.APFMERK14 + ";" + TMV.APFMERK15 + ";";
                test = pm["WAMVB"].ToString() + ";";
                if (YN == " " || YN == "J")
                {
                    if (!condtions.Contains(test))
                        continue;
                }
                else
                {
                    if (condtions.Contains(test))
                        continue;
                }
                YN = TMV.APFNEGRGRP;
                #endregion 
                found = true;
                currentpos = i;
                break; 
            }
            if (found)
            {
                result = cAPK.KEY;
            }
            else
            {
                result = "";
            }
            return result;  
        }
    }
}
